package cn.com.se.多线程.ThreadPool.ThreadLocal;

public class ThreadLocalTest {

    // 定义ThreadLocal
    public static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void test() {

        new Thread(new Runnable() {
            @Override
            public void run() {
                threadLocal.set("1111111");
                System.out.println(Thread.currentThread().getName() + ":" + threadLocal.get());
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                threadLocal.set("2222222");
                System.out.println(Thread.currentThread().getName() + ":" + threadLocal.get());
            }
        }).start();
    }


    public static void main(String[] args) {
        // 一个线程只能取到他自己的threadLocal
        test();
    }

}
